package com.atguigu.lease.common.context;

/**
 * @author kk
 * #date 2024/6/23 20:17
 */
/*
* 在本地线程中维护loginUser(登录用户)的数据
* */
public class LoginUserContext {
    private static final ThreadLocal<LoginUser> threadLocal = new ThreadLocal<>();
    //把loginUser的信息保存到threadLocal中
    public static void setUser(LoginUser loginUser){
        threadLocal.set(loginUser);
    }

    //从threadLocal中获取loginUser的信息
    public static LoginUser getUser(){
        LoginUser loginUser = threadLocal.get();
        return loginUser;
    }

    //从threadLocal中删除loginUser的信息
    public static void removeUser(){
        threadLocal.remove();
    }
}
